use rbatis::RBatis;
use rbdc_pg::PgDriver;
use serde::{Deserialize, Serialize};
pub mod user;
pub mod command;

#[derive(Debug,Serialize,Deserialize)]
pub struct Resp<T>{
    pub status:i32,
    pub msg:String,
    pub data: Vec<T>,
}
impl<T> Resp<T> {
    pub fn new(status:i32,msg:String,data:Vec<T>) -> Self {
        Resp { 
            status, 
            msg, 
            data,
         }
    }
    pub fn set_statust(&mut self,status:i32){
        self.status=status;
    }
    pub fn set_msg(&mut self,msg:String){
        self.msg=msg;
    }
    pub fn set_data(&mut self,data:Vec<T>){
        self.data=data;
    }
}

pub struct Database {
    pub db:RBatis,
}

impl Database {
    pub async fn new() -> Self{
        let rb = RBatis::new();
        rb.link(PgDriver{}, "postgres://zeng:zenghaifeng@127.0.0.1:5432/postgres").await.unwrap();
        return Database{
            db:rb
        };
    }
}